#include <stdio.h>
#define D(s) s=p[e++]-48;while(p[e]!=32&&p[e])s=10*s+p[e++]-48;e++;

void main()
{
	char p[100];
	unsigned long long t,x,a,b,res[0xffff];
	unsigned int e=0,ce,resn=0;
	gets(p);
	D(t)
	while(t--)
	{
		gets(p);
		e=0;ce=e;
		D(x)ce=e-ce;D(a)D(b)
		res[resn]=0;
		memset(p,48,100);
		p[0]=49;
		p[ce]=0;
		e=0;
		D(ce)
		if(x>=a&&x<=b)
			res[resn]++;
		res[resn++]+=(b-a)/ce;
	}
	for (e=0;e<resn-1;e++)
		printf("%d\n",res[e]);
	printf("%d",res[e]);
}